<?php 

namespace pmvc\aop;

use pmvc\ioc\ObjectPostProcessor;

abstract class AbstractObjectProxyPostProcessor
	implements ObjectPostProcessor {

	private $interfaces			= NULL;
	private $userData			= NULL;

	protected abstract function shouldProxy($name, $id, $object);
	protected abstract function createMethodInterceptor($name, $id, $object);

	function processBeforeInitialization($name, $id, $object) {
		// do - nothing
	}

	function processAfterInitialization($name, $id, $object) {
		if ($this->shouldProxy($name, $id, $object)) {
			return ProxyUtil::dynamicProxy(
				$this->createMethodInterceptor($name, $id, $object),
				NULL,
				$this->interfaces, $object, $this->userData);
		}
		return FALSE;
	}

	function setInterfaces(Array $interfaces) {
		$this->interfaces = $interfaces;
	}

	function setInterface($interface) {
		$this->setInterfaces(Array($interface));
	}

	function setUserData($userData) {
		$this->userData = $userData;
	}

}

?>